package com.situ.company.project.service.impl;


import java.util.List;


import com.situ.company.project.dao.IProjectDao;
import com.situ.company.project.dao.impl.ProjectDaoImpl;
import com.situ.company.project.model.ProjectModel;
import com.situ.company.project.service.IProjectService;

public class ProjectServiceImpl implements IProjectService{

	private IProjectDao dao = new ProjectDaoImpl();
	@Override
	public String insert(ProjectModel model) {
		if(selectModel(model)==null) {
			Integer res = dao.insert(model);
			return res ==null?null:res.toString();
		}
		return "repeat";
	}

	public String update(ProjectModel model) {
		return dao.updateAll(model)+"";
	}
	
    public ProjectModel selectModel(ProjectModel model) {
		
		return dao.selectModel(new ProjectModel(model.getCode()));
	}

    public List<ProjectModel> selectList(ProjectModel model) {
		String code = model.getCode();
		model.setCode(code==null? "%":"%"+code+"%");
		String name = model.getName();
		model.setName(name==null? "%":"%"+name+"%");
		List<ProjectModel> list = dao.selectList(model);
		
		return dao.selectList(model);
	}  
    
    public Integer selectCount(ProjectModel model) {
    	ProjectModel m1 = new ProjectModel();
		String code = model.getCode();
		m1.setCode(code==null? "%":"%"+code+"%");
		String name = model.getName();
		m1.setName(name==null? "%":"%"+name+"%");
		return dao.selectCount(m1);
		
	}
    
    public String delete(ProjectModel model) {
		Integer res = dao.delete(model);
		return res ==null?null:res.toString();
		
	}

	
}
